﻿using MediatR;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductAttributesCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductAttributesCommandHandlers
{
    public class ShowProductAttrbutesCommandHandler : IRequestHandler<ShowProductAttrbutesCommand, ApiResult<List<ProductAttributes>>>
    {
        IBaseRepository<ProductAttributes> ProductAttributes;

        public ShowProductAttrbutesCommandHandler(IBaseRepository<ProductAttributes> ProductAttributes)
        {
            this.ProductAttributes = ProductAttributes;
        }

        public async Task<ApiResult<List<ProductAttributes>>> Handle(ShowProductAttrbutesCommand request, CancellationToken cancellationToken)
        {
            var list = ProductAttributes.GetAll().ToList();
            return new ApiResult<List<ProductAttributes>> 
            {
                Code=ApiEnum.success,
                Message="属性查询成功",
                Data=list
            };
        }
    }
}
